Skip to content

Conversation

@sambostock
Copy link
Contributor

Motivation

The check-shims command detects duplicate definitions between shim files and generated RBIs. It correctly ignores duplicates when the shim adds a sig block (since the shim is adding type information, not just duplicating). However, it doesn't recognize RBS comment syntax (#:) as a signature, so shims using RBS syntax are incorrectly flagged as duplicates.

With Sorbet's RBS support, users can now write type signatures using RBS comments instead of sig blocks. The check-shims command should treat these equivalently.

Implementation

Modified has_duplicated_methods_and_attrs? in RBIFilesHelper to check for RBI::RBSComment instances in a node's comments array, in addition to checking the sigs array. The logic mirrors the existing signature handling:

  • A shim with an RBS comment is not considered a duplicate of an untyped method (it's adding type info)
  • A shim with a different RBS signature is not a duplicate (it's refining the type)
  • A shim with an identical RBS signature is flagged as a duplicate

Added a small helper method extract_rbs_comments to extract RBS comments from a node.

Tests

Added 3 new tests mirroring the existing sig block tests:

  • ignores duplicates that have an RBS signature
  • ignores duplicates that have a different RBS signature
  • detects duplicates that have the same RBS signature

The check-shims command now recognizes RBS comment syntax (#:) in
addition to Sorbet's sig blocks when determining if a shim is adding
type information versus duplicating existing definitions.

This ensures shims using RBS syntax like `#: () -> void` are treated
the same as shims using `sig { void }` - they won't be flagged as
duplicates if they're adding type information to an untyped method.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@sambostock sambostock requested a review from a team as a code owner January 7, 2026 18:07

# Another prop has the same RBS comment, we have a duplicate
other_rbs_comments = extract_rbs_comments(node)
return true if shim_rbs_comments.any? { |rbs| other_rbs_comments.include?(rbs) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return true if shim_rbs_comments.any? { |rbs| other_rbs_comments.include?(rbs) }
return true if shim_rbs_comments.intersect?(other_rbs_comments)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately intersect? won't work here because RBI::RBSComment implements == but not eql?/hash:

c1 = RBI::RBSComment.new('() -> void')
c2 = RBI::RBSComment.new('() -> void')

c1 == c2           # => true
[c1].include?(c2)  # => true  (uses ==)
[c1].intersect?([c2])  # => false (uses eql?/hash)

I've added a comment to explain this.

@sambostock sambostock added the enhancement New feature or request label Jan 7, 2026
RBI::RBSComment implements == but not eql?/hash, so intersect?
(which uses Set-like comparisons) won't work correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants